package com.ctshk.sapp.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.tour.req.TripCostSharingReq;
import com.ctshk.rpc.tour.req.TripSupplementReq;
import com.ctshk.rpc.tour.service.ISeriesTripDefaultCostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 成本分摊默认 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-15
 */
@Api(value = "成本分摊默认", tags = "成本分摊默认")
@RestController
@RequestMapping("/series/trip/default/cost")
public class SeriesTripDefaultCostController extends BaseController {

    /**
     * 成本分摊默认
     */
    @DubboReference
    private ISeriesTripDefaultCostService seriesTripDefaultCostService;

    @ApiOperation(value = "新增行程-成本分摊", notes = "新增行程-成本分摊")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "新增行程-成本分摊", operDesc = "新增行程-成本分摊")
    @PostMapping("/add/sharing")
    public Result addSharing(@RequestBody @Valid TripCostSharingReq tripCostSharingReq) {
        try {
            return seriesTripDefaultCostService.addSharing(tripCostSharingReq,getCurrentUser(getRequest()));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "查询-成本分摊", notes = "查询-成本分摊")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "查询-成本分摊", operDesc = "查询-成本分摊")
    @GetMapping("/sharing/{id}")
    public Result<TripCostSharingReq> sharing(@PathVariable Long id) {
        return Result.success(seriesTripDefaultCostService.sharing(id));
    }


}
